package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.CustomerDao;
import com.atguigu.jxc.entity.Customer;
import com.atguigu.jxc.service.CustomerService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @Author zhmwi
 * @Date 2021/9/4
 * @Dersciption
 */
@Service
public class CustomerServiceImpl implements CustomerService {

    @Autowired
    private CustomerDao customerDao;

    @Override
    public PageInfo<Customer> getCustomerList(Integer page, Integer rows, String customerName) {
        PageHelper.startPage(page,rows);
        List<Customer> customerList = customerDao.selectCustomerList(customerName);
        PageInfo<Customer> pageInfo = new PageInfo<>(customerList);
        return pageInfo;
    }

    //新增客户
    @Override
    public Boolean save(Customer customer) {
        return customerDao.save(customer);
    }

    //更新客户
    @Override
    public Boolean update(Customer customer) {
        return customerDao.update(customer);
    }
    //删除客户
    @Override
    public Boolean delete(String ids) {
        if (StringUtils.isEmpty(ids)){
            return false;
        }
        String[] split = ids.split(",");
        for (String id : split) {
            customerDao.delete(id);
        }
        return true;
    }
}
